import sys

# This simple comment

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def read_ini_file(file):
    with open(file, 'r') as inp:
        lines = [line.rstrip() for line in inp.readlines()]
    return lines


def write_config_to_file(config, file):
    with open(file, 'w') as out:
        print(*config, sep='\n', file=out)


def trim_empty_strings(file):
    config = read_ini_file(file)
    index = 0
    while index < len(config) - 1:
        if config[index].strip() == '' and config[index + 1].strip() == '':
            config = config[:index] + config[index + 1:]
        else:
            index += 1
    while len(config) > 0 and config[0].strip() == '':
        config = config[1:]
    while len(config) > 0 and config[-1].strip() == '':
        config = config[:-1]
    write_config_to_file(config, file)


def get_comment_symbol(filename: str) -> str:
    """
    По умолчанию '#', но если хотя бы одна строка начинается с ';', то ';'
    :param filename: str
    :return: str
    """
    with open(filename) as inp:
        lines = inp.readlines()
        for line in lines:
            if line.strip().startswith(';'):
                return ';'
    return '#'
